<template>
  <div>
    <a-modal
      :title="`批量修改${title}`"
      :destroyOnClose="true"
      :visible="visible"
      :confirm-loading="confirmLoading"
      @ok="handleOk"
      @cancel="handleCancel"
    >
      <div v-if="title === '状态'">
        <a-form :form="form" :label-col="{ span: 7 }" :wrapper-col="{ span: 12 }">
          <a-form-item label="人员状态">
            <a-select style="width: 100%" placeholder="请选择" show-search v-model="status">
              <a-select-option value="1">已接到</a-select-option>
              <a-select-option value="2">已安排</a-select-option>
              <a-select-option value="3">已面试</a-select-option>
            </a-select>
          </a-form-item>
        </a-form>
      </div>
      <div v-else>
        <a-form :form="form" :label-col="{ span: 7 }" :wrapper-col="{ span: 12 }">
          <a-form-item label="渠道来源">
            <a-select v-model="channelId" placeholder="请选择" show-search option-filter-prop="children" :filter-option="filterOption">
              <a-select-option :value="item.id" v-for="(item, index) in Channels" :key="index">{{ item.name }}</a-select-option>
            </a-select>
          </a-form-item>
        </a-form>
      </div>
    </a-modal>
  </div>
</template>
<script>
import { batchUpdate, getAllChannels } from "@/api/outsourcing/outsourcing";
export default {
  data() {
    return {
      Channels: [],
      checkInIds: [],
      status: "",
      channelId: "",
      title: "",
      form: this.$form.createForm(this, { name: "coordinated" }),
      visible: false,
      confirmLoading: false
    };
  },
  methods: {
    filterOption(input, option) {
      return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0;
    },
    getAllChannelsList() {
      getAllChannels({ isNotChannel: true }).then(res => {
        this.Channels = res.data;
      });
    },
    showModal(arr, name) {
      this.title = name;
      this.checkInIds = arr;
      this.visible = true;
      this.getAllChannelsList();
    },
    handleOk(e) {
      let data = {};
      if (this.title === "状态") {
        data = {
          checkInIds: this.checkInIds.map(i => i.id),
          status: this.status,
          id: "all"
        };
      } else {
        data = {
          checkInIds: this.checkInIds.map(i => i.id),
          channelId: this.channelId,
          id: "all"
        };
      }
      this.confirmLoading = true;
      batchUpdate(data)
        .then(res => {
          this.$message.success(res.msg);
          this.visible = false;
          this.$emit("saveOk");
          this.confirmLoading = false;
          this.channelId = "";
          this.status = "";
        })
        .catch(err => {
          this.confirmLoading = false;
          this.$message.error(err.msg);
        });
    },
    handleCancel(e) {
      this.visible = false;
    }
  }
};
</script>
